<template>
    <div>
		<myheader></myheader>
		<!-- 面包屑导航 -->
		<Breadcrumb :datas="datas"></Breadcrumb>

		
	<section class="featured-block text-center">
		
		<div class="container">  
			
			<table>
				<tr	>
					<td>商品名称：</td>
					<td><input type="text" name="name" id="" v-model="name"></td>
				</tr>
				<tr>
					<td>
						商品标签：
					</td>
					<td>
						<TagInput v-model="mytags" type="string" :limit="10" :wordlimit="20" split=',' placeholder='请输入标签，用英文逗号分隔，输入后回车'></TagInput>
					</td>
				</tr>
				<tr>
					<td>商品简介：</td>
					<td><input type="text" name="desc" id="" v-model="desc"></td>
				</tr>
				<tr>
					<td>颜色：</td>
					<td><input type="text" v-model="color"></td>
				</tr>
				<tr>
					<td>号码：</td>
					<td><input type="text" v-model="size"></td>
				</tr>
				<tr>
					<td>季节：</td>
					<td><input type="text" v-model="season"></td>
				</tr>
				<tr>
					<td>价格：</td>
					<td><input type="text" v-model="price"></td>
				</tr>

				<tr>
					<td></td>
					<td>
						<Button @click="submit" color='blue'>提交</Button>
					</td>
					
				</tr>
				
			</table>
		</div>
	</section>
		<myfooter></myfooter>
    </div>
</template>


<script>
import myheader from './myheader';
import myfooter from './myfooter';
import {config,formatXml} from '../config'
export default {
	name:"myprofile",
	components:{
		'myheader':myheader,
		'myfooter':myfooter,
	},
    data () {
    return {
		msg: "这是一个变量",
		datas:[{title:'首页',route:{name:'index'}},
				{title:"添加商品"}
				],
		name:"",
		desc:'',
		color:'',
		size:"",
		season:'',
		price:0,
		cate_id:1,
		//商品标签变量
		mytags:'',
    }
    },
    mounted:function(){
		
	},
	methods:{
		submit(){
			
			//	拼接商品规格
			var parms = {}
			parms['color'] = this.color;
			parms['size'] = this.size;
			parms['season'] = this.season;
			// console.log(parms)

			// 格式化字符串
			parms = JSON.stringify(parms)

			console.log(parms)
			// parms = JSON.parse(parms);
			// console.log(parms)

			//发送请求
			this.axios({
				url:'http://127.0.0.1:8000/addgoods/',
				params:{
					name:this.name,
					desc:this.desc,
					parms:parms,
					price:this.price,
					cate_id:this.cate_id,
				}
			})
			.then(resp=>{
				console.log(resp);	
				this.$Message(resp.data.message)

				//只有商品入库成功，才能添加标签
				// if (resp.data.id) {
					//在这里再次请求
					this.axios({
						url:'http://127.0.0.1:8000/inserttags/',
						params:{
							id:resp.data.id,
							tags:this.mytags,

						}
					}).then(res=>{
						console.log(res)
					})
				// }
				
			}).catch(error=>{
				console.log(error)
			})
		},
		upload(e){
			//发送请求
			this.axios.post('http://127.0.0.1:8000/uploadfile/',param,config)
			.then(resp=>{
				console.log(resp);
			}).catch(error=>{
				console.log(error)
			})
		},
    },
}


</script>


<style>
	td{padding: 5px;}


</style>